﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TodoApp.LiveShopUserInfosDTO;
using TodoApp.TodoLiveShopCategorysDTO;
using TodoApp.UsersModel;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.ObjectMapping;

namespace TodoApp
{
    /// <summary>
    ///  用户信息绑定 实现服务接口 
    /// </summary>
   public  class UserInfosService : Volo.Abp.Application.Services.ApplicationService , IUserInfosService
    {


        private readonly IRepository<LiveShopUserInfos, int> db;
        public UserInfosService(IRepository<LiveShopUserInfos, int> _db) {
            db = _db;
        }

        [HttpPost]
        public int Add(LiveShopUserInfosAddDTO model)
        {
             db.InsertAsync(new LiveShopUserInfos
            {
                Names = model.Names,
                Sex = model.Sex,
                IdCar = model.IdCar,
                Phone = model.Phone,
                Email = model.Email,
                Balance = model.Balance
            });

            return 1;
           
        }

        [HttpDelete]
        public int Del(int id)
        {
            db.DeleteAsync(id);
            return 1;
        }

        [HttpGet]
        public async Task<List<LiveShopUserInfosShowDTO>> Show(string name)
        {
            List<LiveShopUserInfosShowDTO> ls = ObjectMapper.Map<List<LiveShopUserInfos>, List<LiveShopUserInfosShowDTO>>(await db.GetListAsync());
           
            if ( name != null )
            {
                ls = ls.Where(x => x.Names.Equals(name)).ToList();
            }
            return ls; 
        }
        [HttpPut]
        public int Upd(LiveShopUserInfosShowDTO model)
        {
            throw new NotImplementedException();
        }
    }
}
